package util;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * @author 24270
 */
public class JpaUtil {
    private static EntityManagerFactory factory = null;
    static {
        // jpaDemo与persistence.xml中的persistence-unit name对应
        factory = Persistence.createEntityManagerFactory("jpaDemo");
    }
    public static EntityManager getEntityManager() {
        return factory.createEntityManager();
    }
    public void closeResource(EntityManagerFactory factory, EntityManager em) {
        em.close();
        factory.close();
    }
}
